home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / solaris2 / jdk / src / java / lang / object.jav < prev    next >
Encoding:
Text File  |  1995-10-30  |  5.7 KB  |  155 lines

  1. /*
  2.  * @(#)Object.java    1.25 95/08/18  
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package java.lang;
  21.  
  22. /**
  23.  * The root of the Class hierarchy.  Every Class in the system
  24.  * has Object as its ultimate parent.  Every variable and method
  25.  * defined here is available in every Object. 
  26.  * @see        Class
  27.  * @version     1.25, 08/18/95
  28.  */
  29. public class Object {
  30.     /**
  31.      * Returns the Class of this Object. Java has a runtime
  32.      * representation for classes- a descriptor of type Class- 
  33.      * which the method getClass() returns for any Object.
  34.      */
  35.     public final native Class getClass();
  36.  
  37.     /**
  38.      * Returns a hashcode for this Object.
  39.      * Each Object in the Java system has a hashcode. The hashcode
  40.      * is a number that is usually different for different Objects.
  41.      * It is used when storing Objects in hashtables.
  42.      * Note: hashcodes can be negative as well as positive.
  43.      * @see        java.util.Hashtable
  44.      */
  45.     public native int hashCode();
  46.  
  47.     /**
  48.      * Compares two Objects for equality.
  49.      * Returns a boolean that indicates whether this Object is equivalent 
  50.      * to the specified Object. This method is used when an Object is stored
  51.      * in a hashtable.
  52.      * @param    obj    the Object to compare with
  53.      * @return    true if these Objects are equal; false otherwise.
  54.      * @see        java.util.Hashtable
  55.      */
  56.     public boolean equals(Object obj) {
  57.     return (this == obj);
  58.     }
  59.  
  60.     /**
  61.      * Copies the contents of the specified Object into this Object.  The contents
  62.      * of an Object are defined as the values of its instance variables.  The 
  63.      * parameter src must be of the same Class as this Object.
  64.      * @param src the Object whose contents are copied into the current object
  65.      * @exception    ClassCastException If obj is not of the same type as
  66.      *            this Object.
  67.      * @see        Object#clone
  68.      */
  69.     protected native void copy(Object src);
  70.  
  71.     /**
  72.      * Creates a clone of this Object. A new instance is allocated and
  73.      * the copy() method is called to copy the contents of this
  74.      * Object into the clone.
  75.      * @return        a copy of this Object.
  76.      * @exception    OutOfMemoryError If there is not enough memory.
  77.      * @see        Object#copy
  78.      */
  79.     protected native Object clone();
  80.  
  81.     /**
  82.      * Returns a String that represents the value of this Object.  It is recommended
  83.      * that all subclasses override this method.
  84.      */
  85.     public native String toString();
  86.  
  87.     /**
  88.      * Notifies a single waiting thread on a change in condition of another thread. 
  89.      * The thread effecting the change notifies the waiting thread
  90.      * using notify(). Threads that want to wait for a condition to 
  91.      * change before proceeding can call wait(). <p>
  92.      * <em>The method notify() can only be called from within a synchronized method.</em>
  93.      *
  94.      * @exception    InternalError If the current thread is not the owner of the
  95.      *            Object's monitor.
  96.      * @see        Object#wait
  97.      * @see        Object#notifyAll
  98.      */
  99.     public final native void notify();
  100.  
  101.     /**
  102.      * Notifies all of the threads waiting for a condition to change.
  103.      * Threads that are waiting are generally waiting for another thread to 
  104.      * change some condition. Thus, the thread effecting a change that more 
  105.      * than one thread is waiting for notifies all the waiting threads using
  106.      * the method notifyAll(). Threads that want to wait for a condition to 
  107.      * change before proceeding can call wait(). <p>
  108.      * <em>The method notifyAll() can only be called from within a synchronized method.</em>
  109.      *
  110.      * @exception    InternalError If the current thread is not the owner of the
  111.      *            Object's monitor.
  112.      * @see        Object#wait
  113.      * @see        Object#notify
  114.       */
  115.     public final native void notifyAll();
  116.  
  117.     /**
  118.      * Causes a thread to wait until it is notified or the specified timeout
  119.      * expires. <p>
  120.      * <em>The method wait() can only be called from within a synchronized method.</em>
  121.      *
  122.      * @param timeout    the maximum time to wait in milliseconds
  123.      * @exception    InternalError If the current thread is not the owner of the
  124.      *            Object's monitor.
  125.      */
  126.     public final native void wait(long timeout) throws InterruptedException;
  127.  
  128.     /**
  129.      * More accurate wait.
  130.      * <em>The method wait() can only be called from within a synchronized method.</em>
  131.      *
  132.      * @param timeout    the maximum time to wait in milliseconds
  133.      * @param nano      additional time, in nanoseconds range 0-999999
  134.      * @exception    InternalError If the current thread is not the owner of the
  135.      *            Object's monitor.
  136.      */
  137.     public final void wait(long timeout, int nanos) throws InterruptedException {
  138.     if (nanos >= 500000 || (nanos != 0 && timeout==0))
  139.         timeout++;
  140.     wait(timeout);
  141.     }
  142.  
  143.     /**
  144.      * Causes a thread to wait forever until it is notified. <p>
  145.      * <em>The method wait() can only be called from within a synchronized method</em>
  146.      *
  147.      * @exception    InternalError If the current thread is not the owner of the
  148.      *            Object's monitor.
  149.      */
  150.     public final void wait() throws InterruptedException {
  151.     wait(0);
  152.     }
  153. }
  154.  
  155.